home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 30
/
Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso
/
Aminet
/
dev
/
asm
/
ESA.lha
/
ESA
/
examples
/
QuickSort.ei
< prev
next >
Wrap
Text File
|
1998-12-18
|
2KB
|
64 lines
****************************************************************************
* THIS IS NOT A STANDALONE SOURCE!
* You can compile and assemble it, but you can't run it!!!
*
* The procedure below execute the sorting on a vector of 32bit signed inte-
* gers using the QuickSort algorithm.
*
* Note that this is meant to be an example only, so optimization has been
* sacrificed to enhance the readability (btw: ESA isn't indicated at all
* for this kinda things...).
*
* To use it you need an integers vector of any length.
****************************************************************************
****************************************************************************
* QuickSort v1.0.0
****************************************************************************
* INFO sorts in ascending order a vector of signed long integer
* SYNOPSIS QuickSort[Vec, L , R]
* a0 d0 d1
* IN Vec adr of vector to sort
* L Leftmost element index (tipically 0)
* R Rightmost element index (tipically # of integers-1)
* NOTE vector elems are .l
****************************************************************************
procedure QuickSort[a0/d0-d1],d0-d5
move.l d0,d4 ;d4=L; d0=i
move.l d1,d5 ;d5=R; d1=j
move.l d4,d2
add.l d5,d2
lsr.l #1,d2 ;(L+R)/2
move.l (a0,d2.l*4),d2 ;PVT
repeat
while.s (a0,d0.l*4)<d2
addq.l #1,d0 ;inc i
ewhile
while.s (a0,d1.l*4)>d2
subq.l #1,d1 ;dec j
ewhile
when.s d0<=d1 ;if i<j
move.l (a0,d0.l*4),d3
move.l (a0,d1.l*4),(a0,d0.l*4)
move.l d3,(a0,d1.l*4) ;Vec[i] <-> Vec[j]
addq.l #1,d0 ;inc i
subq.l #1,d1 ;dec j
ewhen
until.s d0>d1
when.s d4<d1
QuickSort.s[sav:a0,d4,d1]
ewhen
when.s d0<d5
QuickSort.s[sav:a0,d0,d5]
ewhen
eproc